self.onmessage = function(event){
	// 接收参数
	var account = JSON.parse(event.data);
	if( account.apps ){
		var xhr1, URL = account.URL, sessionId = account.sessionID;
		var params = formatParams( getOfflineMenuParams(account.apps) );
		ajaxOfflineMenu(params,ajaxOfflineMenuCallBack);
	}else if( account.arrTempl ){
		var xhr = [], URL = account.URL, sessionId = account.sessionID;
		var arr = account.arrTempl;
		var url = URL + "followup/service/scheme/queryTemplCont?sessionId=" + sessionId;
		if(arr && arr.length > 0){
	    	for (var i = 0; i < arr.length; i++) {
	    		(function(i){
					xhr[i] = new XMLHttpRequest();
					xhr[i].onreadystatechange = function(){
						if(xhr[i].readyState == 4 && xhr[i].status == 200){      
					        var ret = JSON.parse(xhr[i].responseText);
					        if(ret.success){
					        	var response = ret.data;
					        	response = Object.assign(response,arr[i]);
					        	postMessage( JSON.stringify(response) );
					        }
					    }
					};
					xhr[i].open("post",url,true);
					xhr[i].send(formatParams(arr[i]));
				})(i);
	    	}
		}
	}

	/**
	 * 获取参数
	 */
	function formatParams(params){
		return JSON.stringify({
			data : params
		});
	}

	/**
	 * 获取 OfflineMenu 参数
	 */
	function getOfflineMenuParams(apps){
		if(apps.length > 0){
			for (var i = 0; i < apps.length; i++) {
				if( apps[i].status == 1 ){
					return { "accountId": apps[i].id };
				}
			}
		}
	}

	/**
	 * 请求离线状态时的菜单
	 */
	function ajaxOfflineMenu(params,callBack){
		var url = URL + "followup/service/offline/querySystemOfflineMenu?sessionId=" + sessionId;
		xhr1 = new XMLHttpRequest();
		xhr1.onreadystatechange = callBack;
		xhr1.open("post",url,true);
		xhr1.send(params);
	}

	/**
	 * 查询该系统离线状态时的菜单成功后的回调函数
	 */
	function ajaxOfflineMenuCallBack(){
		if(xhr1.readyState == 4 && xhr1.status == 200){      
	        var data = JSON.parse(xhr1.responseText);
	        if(data.success){
	        	var rows = data.data.rows;
	        	// 发送离线菜单
	        	postMessage( JSON.stringify(rows) );
	        } 
	    }
	}

}